(function() {
  var CollectionView, MyListView, mediator,
    __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };

  mediator = require('mediator');

  CollectionView = require('./../collection_view');

  module.exports = MyListView = (function(_super) {
    var lastSelectedItem;

    __extends(MyListView, _super);

    MyListView.name = 'MyListView';

    function MyListView() {
      return MyListView.__super__.constructor.apply(this, arguments);
    }

    MyListView.prototype.getSelectedItemEventName = function() {};

    MyListView.prototype.clickedItemInternalEventName = null;

    lastSelectedItem = null;

    MyListView.prototype.initialize = function() {
      this.subscribeToControlsEvents();
      return MyListView.__super__.initialize.apply(this, arguments);
    };

    MyListView.prototype.subscribeToControlsEvents = function() {
      this.unsubscribeEvent(this.clickedItemInternalEventName, this.raiseSelectedItemChanged);
      return this.subscribeEvent(this.clickedItemInternalEventName, this.raiseSelectedItemChanged);
    };

    MyListView.prototype.getView = function(view) {
      view.render();
      view.SetSelectedItemChangedEventName(this.clickedItemInternalEventName);
      return view;
    };

    MyListView.prototype.raiseSelectedItemChanged = function(model) {
      if (lastSelectedItem === null || lastSelectedItem.id !== model.id) {
        mediator.publish(this.getSelectedItemEventName(), model);
      }
      return lastSelectedItem = model;
    };

    return MyListView;

  })(CollectionView);

}).call(this);
